//let isChangeEnd = false;
var videoBgSwiper = new Swiper('.video-bg-swiper',{
    effect: 'fade',
    speed: 1000,
    noSwiping: true
})

let motivationSwiper = new Swiper('.motivation-swiper', {
    //initialSlide: 4,
    direction: 'vertical',
    speed: 500,
    parallax: true,
    //autoHeight: true, //高度随内容变化
    // autoplay: {
    //     delay: 4000,
    //     disableOnInteraction: false,
    // },
    mousewheel: true,
    on: {
        init: function (swiper) {
            //Swiper初始化了
            //console.log('当前的slide序号是' + this.activeIndex);//或者swiper.activeIndex，swiper与this都可指代当前swiper实例
        },
        slideChangeTransitionStart: function () {
            //isChangeEnd = false
            const navIsHide = this.isBeginning || this.isEnd;
            //console.log(navIsHide)
            if (!navIsHide) {
                $('.motivation-swiper-navigation').fadeIn()
                
            } else {
                $('.motivation-swiper-navigation').fadeOut()
                $('.video-bg-swiper').removeClass('show')
            }

            if(this.isEnd){
                $('.video-bg-swiper').addClass('hide')
            }else{
                if($('.video-bg-swiper').hasClass('hide')){
                    $('.video-bg-swiper').removeClass('hide')
                }  
                videoBgSwiper.slideTo(this.activeIndex, 1500, false);  
            }

        },
        slideChangeTransitionEnd: function () {

            $('.motivation-swiper-navigation .item').eq(this.activeIndex - 1).addClass('active').siblings().removeClass('active')

            if (this.isEnd) {
                $('.header').addClass('scrolling')
            } else {
                $('.header').removeClass('scrolling')
            }

        },
        touchEnd: function (event) {
            
        },
    }
})

var motivationSwiperNavItem = $('.motivation-swiper-navigation .item').click(function () {
    let idx = parseInt(motivationSwiperNavItem.index(this) + 1)
    motivationSwiper.slideTo(idx, 500, true);
})


var footerSwiper = new Swiper(".footer-scroll-swiper", {
    direction: "vertical",
    slidesPerView: "auto",
    freeMode: true,
    nested: true,
    resistanceRatio: 0,
    scrollbar: {
        el: ".footer-scroll-swiper .swiper-scrollbar",
    },
    mousewheel: true,
});

// var isToTop = false

// function scrollToFooter() {
//     const h = $('.motivation-swiper').height()
//     $('html,body').animate({
//         scrollTop: h
//     }, 500)
// }

// function scrollToTop() {
//     $('html,body').animate({
//         scrollTop: 0
//     }, 500)
//     isToTop = false
// }

// $('.motivation-swiper').on('mousewheel', function (event) {
//     console.log(event.deltaY+"，isChangeEnd"+isChangeEnd);
//     if (event.deltaY == '-1' && motivationSwiper.isEnd && isChangeEnd) {
//         //console.log('滚动到底部版权模块')
//         scrollToFooter()
//     }
// });

// $(window).scroll(function () {
//     var winH = $(window).height()
//     var __scrollTop = $(window).scrollTop()
//     //console.log(winH)
//     if (__scrollTop > winH * 0.9) {
//         if (!isToTop) isToTop = true
//     } else {
//         if (isToTop) scrollToTop()
//     }
// })